package thread;

// 创建线程对象, 并命名
public class demo6 {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            while (true) {
                System.out.println("t1");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"线程1");

        Thread t2= new Thread(() -> {
            while (true) {
                System.out.println("t2");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"线程2");

        Thread t3 = new Thread(() -> {
            while (true) {
                System.out.println("t3");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"线程3");

        t1.start();
        t2.start();
        t3.start();

        while (true) {
            System.out.println("主线程main方法被执行了");
            Thread.sleep(1000);
        }
    }
}
